outsideworkers <- cvl_lodes %>%
filter(w_county %in% cvlfips == F)
Below I show the percentile calculations for Virginia counties based on the number of Charlottesville area residents who are employed in that county. These calculations do not include the number of Charlottesville area residents who are employed within the Charlottesville region. For example, the number of people who live in Albemarle County and commute to Charlottesville City are not reflected in this calculations. The bar graphs show the most common and least common work-destination counties for Charlottesville area residents who work outside of the Charlottesville area.
quantile(na.omit(outsideworkers$commuters), probs = seq(0, 1, by= 0.05))
## 0% 5% 10% 15% 20% 25% 30% 35% 40% 45%
## 2.00 3.25 5.00 13.50 17.00 24.00 26.50 31.00 37.00 45.25
## 50% 55% 60% 65% 70% 75% 80% 85% 90% 95%
## 63.50 68.25 103.00 126.75 152.50 231.75 344.00 487.75 766.50 1167.50
## 100%
## 3565.00
Bottom 25th percentile (the least common work-destinations for Charlottesville area residents)
# Counties that are in the bottom 25th percentile in terms of number of Charlottesville region residents commuters.
outsideworkers25 <- outsideworkers[which(outsideworkers$commuters <= quantile(na.omit(outsideworkers$commuters), probs = 0.25)),]
ggplot(outsideworkers25, aes(x = NAME, y = commuters))+
geom_bar(stat = 'identity', width = 0.5) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "County", y = "Charlottesville area resident commuters")
Top 75th percentile (the most common work-destinations for Charlottesville area residents who work outside the Charlottesville region)
# Counties that are in the top 75th percentile in terms of number of Charlottesville region residents commuters.
outsideworkers75 <- outsideworkers[which(outsideworkers$commuters >= quantile(na.omit(outsideworkers$commuters), probs = 0.75)),]
ggplot(outsideworkers75, aes(x = NAME, y = commuters))+
geom_bar(stat = 'identity', width = 0.5) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
labs(x = "County", y = "Charlottesville area resident commuters")
The map offers another way to visualize where Charlottesville area residents who work outside the Charlottesville region are commuting most often. The counts of Charlottesville area residents who commute to work within the Charlottesville region are excluded from the legend so as to limit the range and allow for easier discrimination between the surrounding counties, but the number of commuters to each of the localities in the Charlottesville region is available by clicking on the locality.
cvllodesmap <- cvl_lodes
cvllodesmap$commuters <- ifelse(cvllodesmap$w_county %in% cvlfips, NA, cvllodesmap$commuters)
pal <- colorNumeric("plasma", reverse = TRUE, na.color = "lightgray", domain = cvllodesmap$commuters)
leaflet(cvl_lodes) %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = cvllodesmap,
fillColor = ~pal(commuters),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
highlight = highlightOptions(
weight = 1, fillOpacity = 0.8, bringToFront = T
),
popup = paste0("County: ", cvllodesmap$NAME, "<br>",
"Number of commuters: ", cvl_lodes$commuters)) %>%
addLegend("bottomright", pal = pal, values = cvllodesmap$commuters,
title = "Number of Charlottesville <br> region commuters", opacity = 0.7)